package com.company.word.dao;

import java.sql.*;

import com.company.word.pojo.User;
import com.company.word.utils.JDBCUtils;


public class UserDAOImpl implements IUserDAO{

	@Override
	public User login(String username, String password) throws SQLException 
	{
		// 1.
		System.out.println("***111***");
		System.out.println(JDBCUtils.getConnection());
		System.out.println("***222***");
		Connection conn = JDBCUtils.getConnection();
		System.out.println("***222***");
		// 2. 
		String sql = "select * from user where username=? and password=?";
		PreparedStatement stmt = conn.prepareStatement(sql);
		stmt.setString(1, username);
		stmt.setString(2, password);
		// 3. 
		ResultSet rs = stmt.executeQuery();
		User user = null;
		if(rs.next())
		{
			int id = rs.getInt(1);
			user = new User(id,username,password);
		}
		
		return user;
	}

}
